﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using CompactFramework.Utilities.Localization;
using System.Reflection;
using System.IO;

namespace TripLOAMobile
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main()
        {
            TestResources();

            ResourceManager.Instance.CallingAssembly = Assembly.GetExecutingAssembly();
            Application.Run(new Welcome());
            
            //se vuoi provare l'animazione...
            //Application.Run(new FormStupidaPerProvareAnimazione());

            //Test.TestEncodedSerialization();
        }

        /// <summary>
        /// Tests the existence of localization resources with the correct names.
        /// The test is used to rename localization resources on the first launching, after installation.
        /// </summary>
        static void TestResources()
        {
            System.Text.StringBuilder str = new System.Text.StringBuilder(256);
            str.Append(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName));
            int baseLen = str.Length;

            string baseRes = str.Append(string.Format("{0}en-US{0}TripLOAMobile.resources_en.dll", Path.DirectorySeparatorChar)).ToString();

            if (File.Exists(baseRes))
            {
                string destRes = str.Remove(str.Length - 7, 7).Append(".dll").ToString();
                File.Move(baseRes, destRes);
            }

            str.Remove(baseLen, str.Length-baseLen);
            baseRes = str.Append(string.Format("{0}it-IT{0}TripLOAMobile.resources_it.dll", Path.DirectorySeparatorChar)).ToString();
            if (File.Exists(baseRes))
            {
                //string destRes = baseRes.Insert(baseRes.Length - 7, ".dll");
                string destRes = str.Remove(str.Length - 7, 7).Append(".dll").ToString();
                File.Move(baseRes, destRes);
            }
        }
    }
}